package com.fudan.dao;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.fudan.ext.entities.Room;
import com.fudan.tool.DozerUtil;

@Repository
public class RoomDaoImpl {
	
	@Autowired
	private RoomRepository roomRepository;
	
	public List<com.fudan.dto.entities.Room> getAllRooms(){
		List<Room> rooms = roomRepository.findAll();
		
		return DozerUtil.transforList(rooms, com.fudan.dto.entities.Room.class);	
		
	}
	
	
	public com.fudan.dto.entities.Room save(com.fudan.dto.entities.Room room ) {
		
		Room daoRoom = DozerUtil.transfor(room, Room.class);
		
		daoRoom = roomRepository.save(daoRoom);
	
		
		
		room = DozerUtil.transfor(room, com.fudan.dto.entities.Room.class);
		
		return room;
	}
	
	
	public com.fudan.dto.entities.Room getRoomId(Integer roomId) {
		
		
		Optional<Room> room = roomRepository.findById(roomId);
		
		com.fudan.dto.entities.Room room1 = DozerUtil.transfor(room.get(), com.fudan.dto.entities.Room.class);
		
		return room1;
	}

}
